{extend name="admin@public/basic" /}
{block name="style"}{/block}
<!-- <link rel="stylesheet" href="__STATIC__/css/admin/public.css" media="all"/> -->

{block name="cotent"}
<link rel="stylesheet" href="__STATIC__/css/admin/public.css" media="all"/>

<form id="form" class="layui-form" style="width:80%;">
    <div class="layui-tab">
        <ul class="layui-tab-title">
            <li class="layui-this">基本信息</li>
        </ul>
        <div class="layui-tab-content ">
            <!--基本信息-->
            <div class="layui-tab-item layui-show">
                <input type="hidden" id="app_sn" value="{$app_sn}"/>
                <div class="layui-form-item layui-row layui-col-xs12">
                    <label class="layui-form-label">生成方式</label>
                    <div class="layui-input-block type">
                        <input type="radio" name="type" value="1" title="单个" checked lay-filter="selectType">
                        <input type="radio" name="type" value="2" title="批量" lay-filter="selectType">
                    </div>
                </div>
                <div class="layui-form-item layui-row layui-col-xs12">
                    <label class="layui-form-label">所属企业</label>
                    <div class="layui-input-block company_id">
                        <select name="company_id" class="company_id">
                            {volist name='$company_list' id='v'}
                            <option value="{$v.company_id}" label="{$v.short_name_en}">{$v.company_name}</option>
                            {/volist}
                        </select>
                    </div>
                </div>
                <div class="layui-form-item layui-row layui-col-xs12">
                    <label class="layui-form-label">区域</label>
                    <div class="layui-input-block">
                        <input type="text" name="region" class="layui-input region" lay-verify="required" value="" placeholder="请输入区域简写">
                        <div style="color:red">如：重庆区域简写CQ</div>
                    </div>
                </div>
                <div class="layui-form-item layui-row layui-col-xs12">
                    <label class="layui-form-label" id="lable"></label>
                    <div class="layui-input-block">
                        <input type="text" name="qrcode_no" class="layui-input qrcode_no" lay-verify="required" value="" placeholder="请输入二维码编号/前缀">
                        <div style="color:red">二维码编号默认是8位数字，前缀默认是2位数字</div>
                    </div>
                </div>
                <div class="layui-form-item layui-row layui-col-xs12" id="num" hidden>
                    <label class="layui-form-label">数量</label>
                    <div class="layui-input-block">
                        <input type="text" name="num" class="layui-input num" lay-verify="required" value="" placeholder="请输入数量">
                    </div>
                </div>

                <input type="hidden" class="id" name="id" value="{$data.id|default=''}">
            </div>

        </div>
    </div>


    <div class="layui-form-item layui-row layui-col-xs12">
        <div class="layui-input-block">
            <button class="layui-btn layui-btn-sm" lay-submit="" id="addUser">确定</button>
            <button type="reset" class="layui-btn layui-btn-sm layui-btn-primary">取消</button>
        </div>
    </div>
    </div>
</form>

{/block}

{block name="script"}
<script type="text/javascript" src="__STATIC__/layuicms/layui/layui.js"></script>
<script type="text/javascript" src="__STATIC__/plugs/webuploader.min.js"></script>

<script>

    layui.use(['form','layer','layedit','upload','element'],function(){
        var form = layui.form,
            layer = parent.layer === undefined ? layui.layer : top.layer,
            laypage = layui.laypage,
            upload = layui.upload,
            layedit = layui.layedit,
            element = layui.element,
            $ = layui.jquery;

        //一些事件监听
        element.on('tab(demo)', function (data) {
            console.log(data);
        });

        /**
         * 新增以及编辑后台用户
         */
        $("#addUser").click(function () {
            var url = '{:url("$thisClass/add_qrcode")}';
            var loadingFlag= parent.layer.msg('生成中，请稍候……', { icon: 16, shade: 0.01,shadeClose:false,time:20000 });
            //layui.layer.load();
            var data = {
                id: $(".id").val(),
                qrcode_no: $(".qrcode_no").val(),
                type: $('input[name="type"]:checked').val(),
                company_id:$('.company_id option:selected').val(),
                //short_name_en:$('.company_id option:selected').attr('label'),
                region:$('.region').val(),
                num:$('.num').val(),
                app_sn:$('#app_sn').val(),
            };
            if(data.qrcode_no.length !=2 && data.qrcode_no.length !=8){
                layer.msg('二维码编号格式不正确!');
            }
            $.ajax({
                url: url,
                method:"POST",
                data: data,
                success:function(res){
                    if(res.code ==1){
                        layer.msg(res.msg,{icon: 1});
                        setTimeout(function(){
                            //刷新父页面
                            parent.location.reload();
                        },500);

                    }else{
                        layer.msg(res.msg);
                    }
                }
            });
            parent.layer.close(loadingFlag);
            return false;
        });

        //初始化
        $('#num').hide();
        $('#lable').text('二维码编号/前缀');

        // 监听选择二维码生成类型
        form.on('radio(selectType)', function (data) {
            var value = data.value;
            if(value==1){
                $('#lable').text('二维码编号/前缀');
                $('#num').hide();//单个
            }else{
                $('#lable').text('前缀');
                $('#num').show();//批量
            }

        });

        form.render();

    });




</script>
{/block}
